package com.beiju.coupon.controller;

import cn.hutool.json.JSONObject;
import com.beiju.coupon.entity.Coupon;
import com.beiju.coupon.service.ICouponService;
import com.beiju.coupon.utils.Result;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSupport;
import io.swagger.annotations.DynamicParameter;
import io.swagger.annotations.DynamicResponseParameters;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * 优惠券信息表控制器
 *
 * @author beiju
 * @date 2021-01-22
 */
@RestController
@RequestMapping("/coupon")
public class CouponController
{
    @Resource
    private ICouponService couponService;

    /**
     * 查询优惠券信息表列表
     */
    @ApiOperation(value="查询优惠券信息表列表", notes="查询优惠券信息表列表")
    @ApiOperationSupport(
            responses = @DynamicResponseParameters(properties = {
                    @DynamicParameter(value = "返回编码",name = "code",example = "200"),
                    @DynamicParameter(value = "返回消息",name = "msg",example = "查询成功"),
                    @DynamicParameter(value = "返回对象",name = "data",dataTypeClass = Coupon.class),
            })
    )
    @PostMapping("/list")
    public Result list(@RequestBody JSONObject params)
    {
        return couponService.list(params);
    }

    /**
     * 获取优惠券信息表详细信息
     */
    @ApiOperation(value="获取优惠券信息表详细信息", notes="获取优惠券信息表详细信息")
    @ApiOperationSupport(
            responses = @DynamicResponseParameters(properties = {
                    @DynamicParameter(value = "返回编码",name = "code",example = "200"),
                    @DynamicParameter(value = "返回消息",name = "msg",example = "查询成功"),
                    @DynamicParameter(value = "返回对象",name = "data",dataTypeClass = Coupon.class),
            })
    )
    @PostMapping(value = "/info")
    public Result getInfo(@RequestBody JSONObject params)
    {
        return  couponService.getInfo(params);
    }

    /**
     * 新增优惠券信息表
     */
    @ApiOperation(value="新增优惠券信息表", notes="新增优惠券信息表")
    @ApiOperationSupport(
            responses = @DynamicResponseParameters(properties = {
                    @DynamicParameter(value = "返回编码",name = "code",example = "200"),
                    @DynamicParameter(value = "返回消息",name = "msg",example = "新增成功"),
                    @DynamicParameter(value = "返回对象",name = "data"),
            })
    )
    @PostMapping("/add")
    public Result add(@RequestBody JSONObject params)
    {
        return couponService.add(params);
    }

    /**
     * 修改优惠券信息表
     */
    @ApiOperation(value="修改优惠券信息表", notes="修改优惠券信息表")
    @ApiOperationSupport(
            responses = @DynamicResponseParameters(properties = {
                    @DynamicParameter(value = "返回编码",name = "code",example = "200"),
                    @DynamicParameter(value = "返回消息",name = "msg",example = "修改成功"),
                    @DynamicParameter(value = "返回对象",name = "data"),
            })
    )
    @PutMapping("/update")
    public Result edit(@RequestBody JSONObject params)
    {
        return couponService.edit(params);
    }

    /**
     * 删除优惠券信息表
     */
    @ApiOperation(value="删除优惠券信息表", notes="删除优惠券信息表")
    @ApiOperationSupport(
            responses = @DynamicResponseParameters(properties = {
                    @DynamicParameter(value = "返回编码",name = "code",example = "200"),
                    @DynamicParameter(value = "返回消息",name = "msg",example = "删除成功"),
                    @DynamicParameter(value = "返回对象",name = "data"),
            })
    )
	@DeleteMapping("/del")
    public Result remove(@RequestBody JSONObject params)
    {
        return couponService.remove(params);
    }
}
